package edu.gdin.ecommerce.dao;

import org.springframework.stereotype.Repository;

import edu.gdin.ecommerce.model.ParamDetail;
import edu.gdin.ecommerce.util.Pager;

@Repository("paramDetailDAO")
public class ParamDetailDAO extends BaseDAO {
	
	public Pager queryParamDetail(ParamDetail pd, int cPage) {
			
			String hql = "from ParamDetail p where 1=1 ";
			
			String pdId = pd.getParamDetailId();
			String pdName = pd.getName();
			String pdValue = pd.getValue();
			String pdDesc = pd.getDetailDesc();
			
			hql += pdId.equals("")? "" : "and p.paramDetailId like '%" + pdId + "%'";
			hql += pdName.equals("")? "" : "and p.name like '%" + pdName +"%'";
			hql += pdValue.equals("")? "" : "and p.value like '%" + pdValue +"%'";
			hql += pdDesc.equals("")? "" : "and p.detailDesc like '%" + pdDesc +"%'";
			
			return	this.getPage(hql, cPage);
		}
	
	public String getValueById(String paramDetailId) {
		ParamDetail detail = (ParamDetail) this.findByPk(ParamDetail.class, paramDetailId);
		if(detail != null) {
			return detail.getValue();
		}
		return null;
	}
	
	
	public String getValueById(String paramDetailId, String defaultValue) {
		ParamDetail detail = (ParamDetail) this.findByPk(ParamDetail.class, paramDetailId);
		if(detail != null) {
			return detail.getValue();
		}
		return defaultValue;
	}
	
	public Pager queryParamDetailByParamTypeId(Integer paramTypeId, Integer cPage) {
		String hql = "from ParamDetail p where 1=1 and p.paramType.paramTypeId = '"+paramTypeId+"'";
		return	this.getPage(hql, cPage);
	}
	
}
